package com.servlet;

import com.dao.BooksUtilsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/PayServlet")
public class PayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getSession().removeAttribute("cart");
        BooksUtilsDao dao = new BooksUtilsDao();
        try {
            dao.deletecart();
        } catch (Exception e) {
            e.printStackTrace();
        }
        double sumprice = (double) request.getSession().getAttribute("sumprice");
        response.getWriter().println("结算成功, 共花费："+sumprice+"元！");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
